//
//  Extension+Int.swift
//  ShiGuangJiaSwift
//
//  Created by point on 2022/8/17.
//

import Foundation
// MARK: Map
public extension Int {
    /**将数字转字符串,当数量大于99的时候显示 99+**/
    func map_MsgCount() -> String? {
        if self == 0 {return nil}
        return self > 99 ? "99+" : String(self)
    }
    
    /**将数字转字符串,当大于10000的时候,除以10000,保留一位小数**/
    func  map_countStr() -> String {
        if self >= 10000 {
            let formatter = NumberFormatter()
            formatter.numberStyle = . decimal
            formatter.maximumFractionDigits = 1 //最大的小数位数
            formatter.roundingMode = .down
            return ((formatter.string(from: NSNumber(value: (Double(self) / 10000.0))))  ?? "") + "w"
        }else{
            return String(self)
        }
    }
    
    func map_Chinese() -> String {
        let chineseNumber = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"]
        let chineseUnit = ["", "十", "百", "千", "万", "亿"]
        var result = ""
        var n = self
        var i = 0
        while n > 0 {
            let m = n % 10
            if i == 0 && m == 0 {
                result = chineseNumber[0] + result
            } else {
                result = chineseNumber[m] + chineseUnit[i] + result
            }
            i += 1
            n /= 10
        }
        return result
    }
}
